import request from '@/js/request'

const BASE_URL = '/model/config/definitions'

/**
 * 获取模型信息
 * @param id
 * @returns {Promise<AxiosResponse<T>>}
 */
export function getModelDefinition(id) {
  return request.get(BASE_URL + '/' + id)
}

/**
 * 保存或更新模型信息
 * @param modelDefinition
 * @param isAdd
 * @returns {Promise<AxiosResponse<T>>}
 */
export function saveAndUpdateModelDefinition(modelDefinition, isAdd) {
  if (isAdd){
    return request.post(BASE_URL, modelDefinition)
  } else {
    return request.put(BASE_URL, modelDefinition)
  }
}

/**
 * 获取子模型列表
 * @param parentId
 * @returns {Promise<AxiosResponse<T>>}
 */
export function getModelDefinitionChildrenData(parentId) {
  return request.get(BASE_URL, {params: {parentId: parentId}})
}

/**
 * 删除给定id的模型
 * @param id
 * @returns {Promise<AxiosResponse<T>>}
 */
export function deleteModelDefinition(id) {
  return request.delete(BASE_URL + '/' + id)
}

/**
 * 发布给定id的模型
 * @param modelId
 * @returns {Promise<AxiosResponse<T>>}
 */
export function publishModel(modelId) {
  return request.post(BASE_URL + '/publishModel', null, { params: {modelId} })
}
